local desc_monvkj_mode = [[
  # 抗金简介
  ___

  军八4个玩家（身份固定为主忠，玩家不足人机补位）对抗4个人机（身份固定为反贼）。当所有反贼死亡后，它们将换将复活并强化然后战斗下一轮挑战组人机直到满足胜利或失败条件。

  胜利条件：反贼全部阵亡且达到设定的挑战组。

  失败条件：主忠全部阵亡。

  战功设定：游戏开始，所有主忠角色获得【战功】技能：锁定技，当你获得某些标记能够强化自身。
    强化标记有：摸牌阶段额外摸牌+x，手牌上限+x，每轮开始获得护盾+x，出牌阶段额外使用杀次数+x，额外杀目标数+x。（x为获得的对应标记数）

  斩将设定：每次出现反贼武将将有概率获得【斩将】技能：锁定技，当你死亡时，杀死你的角色（要有【战功】技能）从3个随机的强化标记选项中选1个获得。

]]
-- local XlkjObj = require "packages/xlkj/XlkjObj"
local U = require "packages/utility/utility"
local MobileSelGenMuty = require "packages/lang/MobileSelGenMuty"
local KJobj = require "packages/lang/KJobj"

--开启测试
local IStest
-- local IStest = "zhaoxiang"
--下一轮战斗准备数据
local nextBattleData = {
  {
    xiandengnum = 1,
    getsameskills = {loyalist = {"kj_gongjue"}},
    getcardnum = {rebel=1},
    getshield = {rebel = 1},
    deadthsing = {rebel = {0,0,1,1}},
  },
  {
    xiandengnum = 1,
    getcardnum = {rebel=7,loyalist=2},
    getshield = {rebel = 1},
    getmaxhp = {rebel = 1},
    getsameskills = {rebel = {"rongzhuangSkill"}},
    deadthsing = {rebel = {0,0,1,1}},
    rongzhuangnum = {rebel = 2},
    bossgens = {"godzhangjiao","caojinyu","tenggongzhu","godganning","zerong","hulao2__godlvbu","ty__sunyi"}
  },
}
--战斗轮数
local battleTurn = #nextBattleData
--当前轮数
local curTurn = 1
--过滤其他卡组（只允许白名单的卡组加入牌堆）
local WHILEcards = {"standard","standard_cards","maneuvering","mobile_derived"}

local monvkj_getLogic = function()
  local monvkj_logic = GameLogic:subclass("monvkj_logic")

  function monvkj_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = {
      { "lord" },
      { "lord", "rebel" },
      { "lord", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "loyalist", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel", "rebel", "rebel" },
      { "loyalist", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "loyalist" },
    }
    room.KJobj = KJobj:new({
      nextBattleData = nextBattleData,
      rebles = 4,
      maxplayers = 4,
      istest = IStest,
    })
  end

  function monvkj_logic:prepareForStart()
    self.room:setTag("@curturn",curTurn)
    self.room:setTag("@battleturn",battleTurn)
    self.room.KJobj:logic_prepareForStart({
      otherbanners = {{"@[:]monvkjbaner_rule","monvkj-intro"},{"@totalbattle",curTurn.."/"..battleTurn},{"@seefriendcardstart",""}}
    })
  end

  function monvkj_logic:prepareDrawPile()
    self.room.KJobj:logic_prepareDrawPile({
      excepts = {},
      whitecards = WHILEcards
    })
  end

  function monvkj_logic:assignRoles()
    local room = Fk:currentRoom()
    local n = #room.players
    local bots,players = {},{}
    for i = 1, n do
      local p = room.players[i]
      if p.id < 0 then
        table.insert(bots,p)
      else
        table.insert(players,p)
      end
    end
    if #players < 4 then
      local subnum = 4 - #players
      for i = 1,subnum do
        table.insert(players,table.remove(bots))
      end
    end
    room.players = {}
    for i = 1, n do
      if i % 2 == 1 then
        room.players[i] = table.remove(players,math.random(1,#players))
      else 
        room.players[i] = table.remove(bots,1)
      end
    end

    local seecampcards = "loyalist"
    for i = 1, n do
      local p = room.players[i]
      p.role = i % 2 == 1 and "loyalist" or "rebel"
      p.role_shown = true
      room:broadcastProperty(p,"role")
    end
    for i = 1, n do
      local p = room.players[i]
      if seecampcards == p.role then
        for _,pr in ipairs(room.players) do
          if p ~= pr and seecampcards == pr.role then
            p:addBuddy(pr)
          end
        end
      end
    end
  end

  function monvkj_logic:chooseGenerals()
    local room = self.room
    room.current = room.players[1]
    MobileSelGenMuty:new({
      generalNum = 14,
      repcount = 1,
      istest = IStest,
      -- openhobbygens = true,
      genpoolname = "MN_XLKJ",
    })
  end
  return monvkj_logic
end
---------------------------------------技能--------------------------------------------
local monvkj_rule = fk.CreateTriggerSkill{
  name = "#monvkj_rule",
  priority = 0.001,
  refresh_events = {fk.RoundStart,fk.BuryVictim,fk.GameStart,fk.GameOverJudge,fk.HpChanged,fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.HpChanged then
      if player == target and player.room.seeskinman then
        local ret = player.room.KJobj:HpChangedEvt(player)
        if ret then
          self.cost_data = ret
          return true
        end
      end 
      return
    end
    if event == fk.RoundStart or event == fk.GameStart then
      return player.seat == 1
    elseif event == fk.BuryVictim or event == fk.Deathed or event == fk.GameOverJudge then
      return player == target
    -- elseif event == fk.DrawInitialCards then
    --   return player == target and player.id < 0 and player.room:getTag("rebotdrawnum") and player.room:getTag("rebotdrawnum") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room.KJobj:roundStart()
    elseif event == fk.Deathed then
      room.KJobj:deaThed(data.who,true)
    elseif event == fk.BuryVictim then
      room.KJobj:buryVictim(data.who)
      -- room.KJobj:roundStart()
    elseif event == fk.GameOverJudge then
      room.KJobj:gameOverJudge()
      local drbySameCamp = function(ro)
        for _,pr in ipairs(room.alive_players) do
          if pr.role == ro then
            room:drawCards(pr,1,self.name)
          end
        end
      end
      drbySameCamp(player.role)
    elseif event == fk.GameStart then
      room.KJobj:gameStart()
    elseif event == fk.HpChanged then
      room.KJobj:changeSkin(player,self.cost_data)
    end
  end,
}
Fk:addSkill(monvkj_rule)

local monvkj_mode = fk.CreateGameMode{
  name = "monvkj_mode",
  minPlayer = 8,
  maxPlayer = 8,
  rule = monvkj_rule,
  logic = monvkj_getLogic,
  whitelist = table.clone(WHILEcards),
  winner_getter = function(self, victim)
    return ""
  end,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 10s", passed = playedTime >= 10 } }
    -- if Self.role ~= "lord" then
      table.insert(surrenderJudge, { text = "1v1: left you alive", passed = true})
    -- end
    return surrenderJudge
  end,
}

Fk:loadTranslationTable{
  ["monvkj_mode"] = "手杀4v4抗人机",
  ["#monvkj_rule"] = "手杀4v4抗人机",
  ["@[:]monvkjbaner_rule"] = "手杀4v4抗人机",
  

  ["monvkj-intro"]="点击介绍",
  [":monvkj-intro"]= desc_monvkj_mode,
  [":monvkj_mode"] = desc_monvkj_mode,
}

return monvkj_mode
